package Sampling;
/**
 * TODO(KADRIYEB)
 * Factory must set parametres using file  
 ***/

import java.util.ArrayList;

import Definitions.GraphClass;
import Global.ConstantVariable;
import Global.GlobalClass;

public class SamplingFactory 
{

	public static SamplingAbstractClass createSamplingWithParameters(GraphClass g, GlobalClass global, String[] parameters)
	{
		 String samplingName = parameters[0];
		 
		 if(samplingName.equals(ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD))
		 {
			 double testRatio = Float.parseFloat(parameters[1]);
			 double valRatio = Float.parseFloat(parameters[2]);
			 double unusedRatio = Float.parseFloat(parameters[3]);
			 double trainRatio = Float.parseFloat(parameters[4]);
			 return new SnowballSamplingClass(g, global, testRatio, valRatio, unusedRatio, trainRatio);
		 }
		 else 
		 {
			 return null;
		 }
	}

	
	public SamplingAbstractClass createSampling (GraphClass g, GlobalClass global, String samplingName, Object...params) {
		
		try{
			
			if(samplingName==ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD) {
				
				double testRatio = (Double)params[0];
				double valRatio=  (Double)params[1];
				double unusedRatio = (Double)params[2];
				double trainRatio = (Double)params[3];
				
				// Using default edge type 
				return new SnowballSamplingClass(g, global, testRatio, valRatio, unusedRatio, trainRatio);
			} else if(samplingName == ConstantVariable.Sampling_Constants.RANDOM_SAMPLING_METHOD) {
				
				/*
				 * 	Random Sampling
				 *	Parametre 1: Name 
				 *	Parametre 2: TestRatio
				 *	Parametre 3: ValRatio
				 *	Parametre 4: Size
				 * */
				
					/*This part must be read in parametre file*/
					/*These are Dummy Parametres */
					double testRatio = (Double)params[0];
					double valRatio= (Double)params[1];					
					double unused = (Double)params[2];
					double trainRatio = (Double)params[3];

					return  new RandomSamplingClass(g, global, testRatio, valRatio, unused, trainRatio);
				}
			else{
				throw new SamplingException("Sampling name (" + samplingName + ") can not be find.");
			}
			
		} catch (SamplingException e) {
			
			System.err.print("Sampling can not be initialize... ");
			e.printStackTrace();
		}
		
		return null;
	}

	

	public SamplingAbstractClass createSampling (ArrayList<Object> parametreList, GraphClass g, GlobalClass global)
	{
		
		
		try
		{
			String name = (String) parametreList.get(0);

			/*TODO (KADRIYEB)
			 * 	//Snowbal sampling parametres must be given like :
				Parametre 1: Name  
				Parametre 2: TestRatio
				Parametre 3: ValRatio
				Parametre 4: EdgeType
				Parametre 5: Degree
				Parametre 6: Threshold
			* */
			
			if(name==ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD)
			{
				/*This part must be read in parametre file*/
				/*These are Dummy Parametres */
				
				double testRatio = (Double)parametreList.get(1);
				double valRatio= (Double)parametreList.get(2);
				double unusedRatio = (Double)parametreList.get(3);
				double trainRatio = (Double)parametreList.get(4);
				
				return new SnowballSamplingClass(g, global, testRatio, valRatio, unusedRatio, trainRatio);
			}
	
			/*
			 * 	Random Sampling
			 *	Parametre 1: Name 
			 *	Parametre 2: TestRatio
			 *	Parametre 3: ValRatio
			 *	Parametre 4: Size
			 * */
			else if(name==ConstantVariable.Sampling_Constants.RANDOM_SAMPLING_METHOD)
			{
				/*This part must be read in parametre file*/
				/*These are Dummy Parametres */
				double testRatio = (Double)parametreList.get(1);
				double valRatio= (Double)parametreList.get(2);
				double unusedRatio= (Double)parametreList.get(3);
				double trainRatio= (Double)parametreList.get(4);
				
				
				return  new RandomSamplingClass( g, global, testRatio, valRatio, unusedRatio, trainRatio);
			}
		}
		catch(Exception e)
		{
			System.out.println("Sampling Method is not define in this system");
		}
		return null;
		
	}
}
